package com.zb.config;


import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;
import org.springframework.amqp.core.*;

@Configuration
public class RabbitConfig {
    //任务表的mq的配置信息 ,完成100%消费数据， 解决了分布式事务，采用最终一致性完成
    public static final String SCORE_ONE_EXCHAGE = "score_one_exchage";
    public static final String SCORE_ONE_QUEUE = "score_one_queue";
    public static final String SCORE_ONE_ROUTING = "score_one_routing";

    @Bean(name = SCORE_ONE_EXCHAGE)
    public Exchange createTaskExchage() {
        return new TopicExchange(SCORE_ONE_EXCHAGE);
    }

    @Bean(name = SCORE_ONE_QUEUE)
    public Queue createTaskQueue() {
        Map<String, Object> params = new HashMap<>();
        return new Queue(SCORE_ONE_QUEUE, true, false, false, params);
    }

    @Bean
    public Binding createTaskBinding(@Qualifier(SCORE_ONE_EXCHAGE) Exchange exchange, @Qualifier(SCORE_ONE_QUEUE) Queue queue) {
        return BindingBuilder.bind(queue).to(exchange).with(SCORE_ONE_ROUTING).noargs();
    }

    //任务表的mq的配置信息 ,完成100%消费数据， 解决了分布式事务，采用最终一致性完成
    public static final String SCORE_TWO_EXCHAGE = "score_two_exchage";
    public static final String SCORE_TWO_QUEUE = "score_two_queue";
    public static final String SCORE_TWO_ROUTING = "score_two_routing";

    @Bean(name = SCORE_TWO_EXCHAGE)
    public Exchange createTaskTwoExchage() {
        return new TopicExchange(SCORE_TWO_EXCHAGE);
    }

    @Bean(name = SCORE_TWO_QUEUE)
    public Queue createTaskTwoQueue() {
        Map<String, Object> params = new HashMap<>();
        return new Queue(SCORE_TWO_QUEUE, true, false, false, params);
    }

    @Bean
    public Binding createTaskTwoBinding(@Qualifier(SCORE_TWO_EXCHAGE) Exchange exchange, @Qualifier(SCORE_TWO_QUEUE) Queue queue) {
        return BindingBuilder.bind(queue).to(exchange).with(SCORE_TWO_ROUTING).noargs();
    }
}
